// src/categories.js
import request from '@/utils/request'

// 1. 分页查询分类
export function pageCategories(params) {
    return request.get('/admin/categories/page', { params })
}

// 2. 获取分类树（可用于父分类下拉）
export function getCategoryTree() {
    return request.get('/admin/categories/tree')
}

// 3. 新增分类
export function addCategory(data) {
    return request.post('/admin/categories', data)
}

// 4. 更新分类
export function updateCategory(data) {
    return request.put('/admin/categories', data)
}

// 5. 删除分类
export function deleteCategory(id) {
    return request.delete(`/admin/categories/${id}`)
}

// 6. 修改分类状态
export function updateCategoryStatus(id, status) {
    return request.put(`/admin/categories/${id}/status/${status}`)
}

// 7. 修改分类排序
export function updateCategorySort(id, sort) {
    return request.put(`/admin/categories/${id}/sort/${sort}`)
}

// 8. 导出 Excel
export function exportCategories() {
    return request.get('/admin/categories/export', { responseType: 'blob' })
}

// 9. 下载导入模板
export function downloadCategoryTemplate() {
    return request.get('/admin/categories/template', { responseType: 'blob' })
}

// 10. 导入 Excel
export function importCategories(file) {
    const form = new FormData()
    form.append('file', file)
    return request.post('/admin/categories/import', form, {
        headers: { 'Content-Type': 'multipart/form-data' }
    })
}
